//
//  ButtonView.swift
//  BodyBuilding
//
//  Created by franze on 2017/10/3.
//  Copyright © 2017年 franze. All rights reserved.
//

import UIKit

class ButtonView: UIView {
    let clubBtn = UIButton()
    let teacherBtn = UIButton()
    let sharingBtn = UIButton()

    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    func initialize(){
        backgroundColor = .white
        
        let w:CGFloat = 75
        let img_w:CGFloat = 44
        let padding = (WIDTH-w*3)/4
        let images = ["club_unselect","sharing_unselect","teacher_unselect"]
        let names = ["俱乐部","晒图","大师"]
        var index = 0
        for button in [clubBtn,teacherBtn,sharingBtn]{
            button.frame = CGRect(x: padding+CGFloat(index)*(padding+w), y: 0, width: w, height: w)
            button.setImage(UIImage(named:images[index])?.scaleImageToSize(CGSize(width: img_w, height: img_w)), for: .normal)
            button.setTitle(names[index], for: .normal)
            button.setTitleColor(.black, for: .normal)
            
            button.titleLabel?.font = UIFont.systemFont(ofSize: 15)
            button.contentVerticalAlignment = .top
            button.contentHorizontalAlignment = .left
            button.imageEdgeInsets = UIEdgeInsetsMake(0, 25/2, 0, 0)
            button.titleEdgeInsets = UIEdgeInsetsMake(img_w, -img_w+22, 0, 0)
            if index == 0{
                button.titleEdgeInsets = UIEdgeInsetsMake(img_w, -img_w+14.5, 0, 0)
            }
            
            button.center.y = bounds.height/2+5
            addSubview(button)
            index += 1
            button.tag = index
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
